function fileUpload(url, fileElement, params, progressCallback, successCallback, errorCallback, canceledCallback) {
  if (!fileElement.files.length)
    throw new Error('请选择文件')
  let formData = new FormData();
  formData.append('file', fileElement.files[0])

  if (params)
    Object.keys(params).forEach(key => {
      formData.append(key, params[key])
    })

  let xhr = new XMLHttpRequest(), ot, oldLoaded;
  xhr.open('post', url, true);
  xhr.onloadstart = () => {
    console.log('开始上传')
    ot = new Date().getTime();   //设置上传开始时间
    oldLoaded = 0;//已上传的文件大小为0
  };

  xhr.upload.addEventListener('progress', progressFunction, false);
  xhr.addEventListener("load", successCallback, false);
  xhr.addEventListener("error", errorCallback, false);
  xhr.addEventListener("abort", canceledCallback, false);
  xhr.send(formData);

  function progressFunction(evt) {
    if (evt.lengthComputable) {
      // 百分比
      let completePercent = Math.round(evt.loaded / evt.total * 100) + '%';

      let time = $("#time");
      let nt = new Date().getTime();     //获取当前时间
      let perTime = (nt - ot) / 1000;        //计算出上次调用该方法时到现在的时间差，单位为s
      ot = new Date().getTime();          //重新赋值时间，用于下次计算

      let perLoad = evt.loaded - oldLoaded; //计算该分段上传的文件大小，单位b
      oldLoaded = evt.loaded;               //重新赋值已上传文件大小

      //上传速度计算
      let speed = perLoad / perTime;//单位b/s
      let baseSpeed = speed;
      let units = 'b/s';//单位名称
      if (speed / 1024 > 1) {
        speed = speed / 1024;
        units = 'k/s';
      }
      if (speed / 1024 > 1) {
        speed = speed / 1024;
        units = 'M/s';
      }
      speed = speed.toFixed(1);
      //剩余时间
      let restTime = ((evt.total - evt.loaded) / baseSpeed).toFixed(1);
      progressCallback && progressCallback({
        completePercent: completePercent,
        restTime: restTime,
        speed: speed
      })
    }
  }
}
